@extends('admin.common.web')

@section('title','用户添加')

@section('content')
<!-- Page Content -->
    <!-- Page Breadcrumb -->
    <div class="page-breadcrumbs">
        <ul class="breadcrumb">
            <li>
                <a href="{{ route('admin.index.index') }}">系统</a>
            </li>
            <li>
                <a href="{{ route('admin.admin.index') }}">用户管理</a>
            </li>
            <li class="active">添加用户</li>
        </ul>
    </div>
    <!-- /Page Breadcrumb -->
    <!-- Page Body -->
    <div class="page-body">

        <div class="row">
            <div class="col-lg-12 col-sm-12 col-xs-12">
                <div class="widget">
                    <div class="widget-header bordered-bottom bordered-blue">
                        <span class="widget-caption">新增用户</span>
                    </div>
                    <div class="widget-body">
                        <div id="horizontal-form">
                            @include('admin.common.msg')
                            @include('admin.common.error')
                            <form class="form-horizontal" action="{{ route('admin.user.store') }}" method="post" onsubmit="return checkForm()" enctype="multipart/form-data">
                                @csrf
                                <div class="form-group">
                                    <label for="username" class="col-sm-2 control-label no-padding-right">姓名</label>
                                    <div class="col-sm-6">
                                        <input class="form-control" value="{{ old('nickname') }}" maxlength="20" autocomplete="off"  name="nickname" required type="text">
                                    </div>
                                    @if($errors->has('nickname'))
                                        <p class="help-block col-sm-4 blue">{{ $errors->first('nickname') }}</p>
                                    @else
                                        <p class="help-block col-sm-4 red">* 必填</p>
                                    @endif
                                </div>

                                <div class="form-group">
                                    <label for="username" class="col-sm-2 control-label no-padding-right">手机号</label>
                                    <div class="col-sm-6">
                                        <input class="form-control" value="{{ old('username') }}" maxlength="11" autocomplete="off"  name="username" required type="text">
                                    </div>
                                    @if($errors->has('username'))
                                        <p class="help-block col-sm-4 blue">{{ $errors->first('username') }}</p>
                                    @else
                                        <p class="help-block col-sm-4 red">* 必填</p>
                                    @endif
                                </div>

                                <div class="form-group">
                                    <label for="username" class="col-sm-2 control-label no-padding-right">登录密码</label>
                                    <div class="col-sm-6">
                                        <input class="form-control" value="{{ old('password') }}" name="password" autocomplete="off" maxlength="16" minlength="6" required type="password">
                                    </div>
                                    @if($errors->has('password'))
                                        <p class="help-block col-sm-4 blue">{{ $errors->first('password') }}</p>
                                    @else
                                        <p class="help-block col-sm-4 red">* 必填</p>
                                    @endif
                                </div>

                                <div class="form-group">
                                    <label for="username" class="col-sm-2 control-label no-padding-right">公司名</label>
                                    <div class="col-sm-6">
                                        <input class="form-control" value="{{ old('company_name') }}" name="company_name" autocomplete="off" maxlength="50" required type="company_name">
                                    </div>
                                    @if($errors->has('company_name'))
                                        <p class="help-block col-sm-4 blue">{{ $errors->first('company_name') }}</p>
                                    @else
                                        <p class="help-block col-sm-4 red">* 必填</p>
                                    @endif
                                </div>

                                <div class="form-group">
                                    <label for="username" class="col-sm-2 control-label no-padding-right">有效期开始时间</label>
                                    <div class="col-sm-6">
                                        <input class="form-control" value="{{ old('start_time') }}" id="start_time" autocomplete="off" name="start_time" required type="start_time">
                                    </div>
                                    @if($errors->has('start_time'))
                                        <p class="help-block col-sm-4 blue">{{ $errors->first('start_time') }}</p>
                                    @else
                                        <p class="help-block col-sm-4 red">* 必填 (时间起始 00:00:00)</p>
                                    @endif
                                </div>

                                <div class="form-group">
                                    <label for="username" class="col-sm-2 control-label no-padding-right">有效期结束时间</label>
                                    <div class="col-sm-6">
                                        <input class="form-control" value="{{ old('end_time') }}" id="end_time" autocomplete="off" name="end_time" required type="end_time">
                                    </div>
                                    @if($errors->has('end_time'))
                                        <p class="help-block col-sm-4 blue">{{ $errors->first('end_time') }}</p>
                                    @else
                                        <p class="help-block col-sm-4 red">* 必填 (时间截止日 00:00:00)</p>
                                    @endif
                                </div>

                                <div class="form-group">
                                    <label for="username" class="col-sm-2 control-label no-padding-right">状态</label>
                                    <div class="col-sm-6">
                                        <div class="radio">
                                            <label>
                                                <input name="status" type="radio" value="1" checked class="colored-blue">
                                                <span class="text">正常</span>
                                            </label>

                                            <label>
                                                <input name="status" type="radio" value="0" class="colored-danger">
                                                <span class="text">锁定</span>
                                            </label>
                                        </div>
                                    </div>
                                    @if($errors->has('status'))
                                        <p class="help-block col-sm-4 blue">{{ $errors->first('status') }}</p>
                                    @endif
                                </div>

                                <div class="form-group">
                                    <div class="col-sm-offset-2 col-sm-10">
                                        <button type="submit" class="btn btn-info">保存信息</button>
                                        <a href="{{ route('admin.user.index') }}" class="btn btn-default">返回</a>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <!-- /Page Body -->
@endsection
@section('script')
    <script type="text/javascript" src="{{ asset('plugins/laydate/laydate.js') }}"></script>

    <script>
        laydate.render({
            elem: '#start_time' //指定元素
        });

        laydate.render({
            elem: '#end_time' //指定元素
        });

        function checkForm() {
            let start_time = $('#start_time').val();
            let end_time = $('#end_time').val();

            if(start_time > end_time){
                layer.msg('开始时间不能大于结束时间');
                return false;
            }

            let tel = $('input[name="username"]').val();
            if(!/^1[3456789]\d{9}$/.test(tel)){
                layer.msg("手机号码有误，请重填");
                return false;
            }

            return true;
        }
    </script>
@endsection
